package com.ebt.m.config;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.ebt.m.R;

/**
 * 初始化客户关系所需数据
 *
 * @author Damon.Han
 */
public class CustomerConfig {
    private static CustomerConfig pConfig;
    private Context context;
    private SharedPreferences sp;
    public static final String LINKERS_RELATIONSHIPS = "linkers_relationships";// 关系
    public static final String LINKERS_INCOME_RESOURCE = "linkers_income_resource";// 收入来源
    public static final String INSURE_LOG_TERMS_FIXED = "insure_log_terms_fixed";// 年期-定期
    public static final String INSURE_LOG_TERMS_PAY_TO = "insure_log_terms_pay_to";// 年期-缴费至
    public static final String INSURE_LOG_PROTECTION_DURING_FIXED = "insure_log_protection_during_fixed";// 保障期间-定期
    public static final String INSURE_LOG_PROTECTION_DURING_PAY_TO = "insure_log_protection_during_pay_to";// 保障期间-缴费至
    public static final String INSURE_LOG_PROTECTION_PERIOD_TO_PAY = "insure_log_period_to_pay";// 期交方式
    public static final String NOTE_NOTE_TYPE = "note_note_type";// 事件类型
    public static final String CAL_ATTENDENCE_SUFFIX = "@e-bao.cn";// 构造日历参与人后缀

    private CustomerConfig(Context context) {
        this.context = context;
    }

    public static CustomerConfig newInstance(Context context) {
        if (pConfig == null) {
            pConfig = new CustomerConfig(context);
        }
        return pConfig;
    }

    /**
     * 入口
     */
    @Deprecated
    public void init() {
        pConfig.initRelationShips();
        pConfig.initIncomeResource();
        pConfig.initTermFixed();
        pConfig.initTermsPayTo();
        pConfig.initProtectionDuringFixed();
        pConfig.initProtextionDuringPayTo();
        pConfig.initProtectionDuringPeriodToPay();
        pConfig.initNoteType();
        Log.e("EBT", "customer初始数据");
    }

    /**
     * 初始化关系
     */
    public void initRelationShips() {
        sp = context.getSharedPreferences(LINKERS_RELATIONSHIPS, Context.MODE_PRIVATE);
        sp.edit().putString("0", "父");
        sp.edit().putString("1", "母");
        sp.edit().putString("2", "子");
        sp.edit().putString("3", "女");
        sp.edit().putString("4", "兄");
        sp.edit().putString("5", "弟");
        sp.edit().putString("6", "姐");
        sp.edit().putString("7", "妹");
        sp.edit().commit();
    }

    /**
     * 初始化收入来源
     */
    public void initIncomeResource() {
        sp = context.getSharedPreferences(LINKERS_INCOME_RESOURCE, Context.MODE_PRIVATE);
        sp.edit().putString("0", "无");
        sp.edit().putString("1", "工资");
        sp.edit().putString("2", "退休金");
        sp.edit().commit();
    }

    /**
     * 初始化年期定期
     */
    public void initTermFixed() {
        sp = context.getSharedPreferences(INSURE_LOG_TERMS_FIXED, Context.MODE_PRIVATE);
        sp.edit().putInt("0", 1);
        sp.edit().putInt("1", 3);
        sp.edit().putInt("2", 5);
        sp.edit().putInt("3", 10);
        sp.edit().putInt("4", 15);
        sp.edit().putInt("5", 20);
        sp.edit().putInt("6", 25);
        sp.edit().putInt("7", 30);
        sp.edit().commit();
    }

    /**
     * 初始化年期-缴费至
     */
    public void initTermsPayTo() {
        sp = context.getSharedPreferences(INSURE_LOG_TERMS_PAY_TO, Context.MODE_PRIVATE);
        sp.edit().putString("0", "50");
        sp.edit().putString("1", "55");
        sp.edit().putString("2", "60");
        sp.edit().putString("3", "65");
        sp.edit().putString("4", "70");
        sp.edit().putString("5", "75");
        sp.edit().putString("6", "80");
        sp.edit().putString("7", "85");
        sp.edit().commit();
    }

    /**
     * 保障期间-定期
     */
    public void initProtectionDuringFixed() {
        sp = context.getSharedPreferences(INSURE_LOG_PROTECTION_DURING_FIXED, Context.MODE_PRIVATE);
        sp.edit().putInt("0", 1);
        sp.edit().putInt("1", 3);
        sp.edit().putInt("2", 5);
        sp.edit().putInt("3", 10);
        sp.edit().putInt("4", 15);
        sp.edit().putInt("5", 20);
        sp.edit().putInt("6", 25);
        sp.edit().putInt("7", 30);
        sp.edit().commit();
    }

    /**
     * 保障期间-保障至
     */
    public void initProtextionDuringPayTo() {
        sp = context.getSharedPreferences(INSURE_LOG_PROTECTION_DURING_PAY_TO, Context.MODE_PRIVATE);
        sp.edit().putString("0", "50");
        sp.edit().putString("1", "55");
        sp.edit().putString("2", "60");
        sp.edit().putString("3", "65");
        sp.edit().putString("4", "70");
        sp.edit().putString("5", "75");
        sp.edit().putString("6", "80");
        sp.edit().putString("7", "85");
        sp.edit().commit();
    }

    /**
     * 保障期间期交方式
     */
    public void initProtectionDuringPeriodToPay() {
        sp = context.getSharedPreferences(INSURE_LOG_PROTECTION_PERIOD_TO_PAY, Context.MODE_PRIVATE);
        sp.edit().putString("0", "月交");
        sp.edit().putString("1", "季交");
        sp.edit().putString("2", "半年交");
        sp.edit().putString("3", "年交");
        sp.edit().putString("4", "趸交");
        sp.edit().commit();
    }

    /**
     * 事件类型
     */
    public void initNoteType() {
        sp = context.getSharedPreferences(NOTE_NOTE_TYPE, Context.MODE_PRIVATE);
        sp.edit().putString("0", "生日");
        sp.edit().putString("1", "车险到期");
        sp.edit().putString("2", "保险续费");
        sp.edit().commit();
    }

    /**
     * 根据性别和年龄获得默认头像
     *
     * @param sex
     * @param age
     * @return
     */
    public static int getPortraitResource(int sex, int age) {
        switch (sex) {
            case 0:// 女
                if (age >= 0 && age < 6) {
                    return R.drawable.female_age_0_6;
                } else if (age >= 6 && age < 18) {
                    return R.drawable.female_age_6_18;
                } else if (age >= 18 && age < 60) {
                    return R.drawable.female_age_18_60;
                } else if (age >= 60) {
                    return R.drawable.female_age_60;
                }
                return R.drawable.customer_2_women_new;
            case 1:// 男
                if (age >= 0 && age < 6) {
                    return R.drawable.male_age_0_6;
                } else if (age >= 6 && age < 18) {
                    return R.drawable.male_age_6_18;
                } else if (age >= 18 && age < 60) {
                    return R.drawable.male_age_18_60;
                } else if (age >= 60) {
                    return R.drawable.male_age_60;
                }
                return R.drawable.customer_2_man_new;
        }
        return R.drawable.customer_2_man_new;
    }

}
